package EnumDemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-07-20
 * Time: 15:33
 */
public enum TestEnum {
    //枚举对象
    RED("红色",1),GREEN,BLUE;
    public String color;
    public int ordinal;
    //枚举的构造方法默认是私有的
    TestEnum(){
    }
    TestEnum(String color,int ordinal){
        this.color=color;
        this.ordinal=ordinal;
    }
    public static void main(String[] args) {
//        TestEnum testEnum=TestEnum.valueOf("green1");
//        System.out.println(testEnum);
        System.out.println(RED.compareTo(GREEN));
    }
    public static void main2(String[] args) {
        //values()：使枚举对象生成一个数组
        TestEnum[] testEnums=TestEnum.values();
        for(int i=0;i<testEnums.length;i++){
            //ordinal()：获取枚举成员的索引位置
            System.out.println(testEnums[i]+"->"+testEnums[i].ordinal());
        }
    }
    public static void main1(String[] args) {
        TestEnum testEnum=TestEnum.BLUE;
        switch (testEnum){
            case RED:
                System.out.println("red");
                break;
            case GREEN:
                System.out.println("green");
                break;
            case BLUE:
                System.out.println("blue");
                break;
            default:
                break;
        }

    }
}
